package yoyo.secret.app.widget;

import yoyo.secret.app.R;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class CustomDialog extends Dialog implements android.view.View.OnClickListener {

	private View.OnClickListener g;
	private View.OnClickListener h;
	Button buttonYes;
	Button buttonNo;
	EditText editText;
	String textInfoString;

	/**
	 * 
	 * @param context
	 * @param resid
	 * @param bool
	 * 
	 */
	public CustomDialog(Context context) {
		super(context, R.style.theme_dialog_alert);

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.pop_dialog);
		setCanceledOnTouchOutside(true);// 设置点击Dialog外部任意区域关闭Dialog

		editText = (EditText) findViewById(R.id.info);

		buttonYes = (Button) findViewById(R.id.ok);
		buttonYes.setOnClickListener(this);

		buttonNo = (Button) findViewById(R.id.cancel);
		buttonNo.setOnClickListener(this);
	}

	@Override
	public void show() {
		Window win = getWindow();
		LayoutParams params = new LayoutParams();
		params.x = 0;// 设置x坐标
		params.y = -800;// 设置y坐标
		win.setAttributes(params);
		super.show();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {

		}
		return false;
	}

	@Override
	public void setTitle(CharSequence title) {
		super.setTitle(title);
	}

	public void setOkOnclick(View.OnClickListener paramOnClickListener) {
		this.g = paramOnClickListener;
	}

	public void setCancelOnclick(View.OnClickListener paramOnClickListener) {
		this.h = paramOnClickListener;
	}

	public String getContent() {
		return editText.getText().toString();
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.ok:
			Log.d("", "R.id.button_yes");
			this.g.onClick(v);

			this.dismiss();

			break;
		case R.id.cancel:
			Log.d("", "R.id.button_no");
			this.dismiss();
			if (this.h != null) {
				this.h.onClick(v);
			}

			break;
		default:
			break;
		}
	}
}
